package com.house.service;

import com.house.util.MD5Utils;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.password.PasswordEncoder;

public class PasswordEncoderimpl implements PasswordEncoder {
    //加密(外面调用一般在注册的时候加密前端传过来的密码保存进数据库)
    @Override
    public String encode(CharSequence rawPassword){
        return MD5Utils.md5(rawPassword.toString());
    };

    //加密前后对比(一般用来比对前端提交过来的密码和数据库存储密码, 也就是明文和密文的对比)
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword){
        return encodedPassword.equals(MD5Utils.md5(rawPassword.toString()));
    }
}
